package huaweiod.first;

import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

/**
 * 华为机试真题 Java 实现【连接器问题】【2022.11 Q4新题】
 */
public class A_2023_23_CouplerProblem {

    public static void main(String[] args) {
        // 处理输入
        Scanner in = new Scanner(System.in);
        String input_ranges = in.nextLine();
        input_ranges = input_ranges.replace("[", "");
        input_ranges = input_ranges.replace("]", "");
        String[] str_ranges = input_ranges.split(",");
        //链接器初始化
        String input_connectors = in.nextLine();
        input_connectors = input_connectors.replace("[", "");
        input_connectors = input_connectors.replace("]", "");
        String[] str_input_connectors = input_connectors.split(",");

        // process
        List<Integer[]> ranges = new ArrayList<>();
        for (int i = 0; i < str_ranges.length; i++) {
            if (i % 2 != 0) {
                Integer[] range = new Integer[]{Integer.valueOf(str_ranges[i - 1]), Integer.valueOf(str_ranges[i])};
                ranges.add(range);
            }
        }
        ranges.sort((a, b) -> a[0] - b[0]);
        // 每个管的距离
        List<Integer> distinct = new ArrayList<>();
        int result = 0;
        int right = ranges.get(0)[1];
        for (int i = 1; i < ranges.size(); i++) {
            if (ranges.get(i)[0] > right) {
                result++;
                distinct.add(ranges.get(i)[0] - right);
            }
            right = ranges.get(i)[1];
        }
        result++;
        // 连接器处理
        List<Integer> connect = new ArrayList<>();
        for (String str_input_connector : str_input_connectors) {
            connect.add(Integer.valueOf(str_input_connector));
        }
        // 贪心算法
        distinct.sort((a, b) -> a - b);
        connect.sort((a, b) -> a - b);
        int index = 0;
        for (Integer integer : connect) {
            if (integer >= distinct.get(index)) {
                index++;
                result--;
            }
        }
        System.out.println(result);
    }
}
